var compscene_month = ''
var ben_value_lmonth = '', ben_value_lylmonth = '', ben_value_pmonth = '', yArr7_3month = '', yArr7_2month = '', yArr7_1month = ''
N.complain2 = N.Class.extend({
    resize: function () {
        // var topheight = $(".container-fluid").height() - $(".content-header").height() - 5;
        var topheight = $('.container-fluid').height() - 20
        var bottomheight = topheight * (1 / 2)
        var boxtop = bottomheight - 120
        var maptop = topheight * (2 / 3) - 60
        var mapbot = topheight * (1 / 3) - 60
        $('.control-size-box').height(boxtop)
        $('.control-size-box-map').height(maptop)
        $('.control-size-box-mapbot').height(mapbot)

        var headheight = $('#table1_wrapper .dataTables_scrollHeadInner').height()
        if (headheight) {
            this.tablbeHeight = boxtop - headheight - 5
            $('#table1_wrapper .dataTables_scrollBody').height(this.tablbeHeight)
        }
        headheight = $('#table2_wrapper .dataTables_scrollHeadInner').height()
        if (headheight) {
            this.tablbeHeight = boxtop - headheight - 5
            $('#table2_wrapper .dataTables_scrollBody').height(this.tablbeHeight)
        }
    },
    pageLoad: function (geography, shiduan, geo_dim, city, area) {
        loading.show()
        this.geographyChart(shiduan, geo_dim, city, area)
    },
    geographyChart: function (shiduan, geo_dim, city, area) {
        var param
        if (geo_dim === '省') {
            param = {
                geo_dim: '省',
                time_dim: shiduan,
                area: area
            }
        } else if (geo_dim === '地市' || geo_dim === '区县') {
            param = {
                geo_dim: '地市',
                time_dim: shiduan,
                city: city,
                area: area
            }
        }
        console.log('时间维度:' + param.time_dim + '；地理纬度:' + param.geo_dim + '；市:' + param.city + '；区县:' + param.area)
        $.ajax({
            url: getApiPath() + 'complain/monthGeographyChart',
            type: 'get',
            data: param,
            cache: false,
            dataType: 'json',
            success: function (result) {
                console.log(result)
                // 横坐标
                var xArr1 = []
                // 纵坐标
                var ben_value_lm = [], ben_value_pm = [], ben_value_lylm = []
                ben_value_lmonth = '', ben_value_lylmonth = '', ben_value_pmonth = ''
                if (result.comwoben_d_list) {
                    $.each(result.comwoben_d_list, function (index, value) {
                        ben_value_lm.push(value.ben_value_lm)
                        ben_value_pm.push(value.ben_value_pm)
                        ben_value_lylm.push(value.ben_value_lylm)
                        xArr1.push(value.ben_time)
                    })
                    if (result.comwoben_d_list.length > 0) {
                        ben_value_lmonth = result.comwoben_d_list[0].ben_value_lmonth
                        ben_value_lylmonth = result.comwoben_d_list[0].ben_value_lylmonth
                        ben_value_pmonth = result.comwoben_d_list[0].ben_value_pmonth
                    }
                }

                var xArr2 = []
                var yArr2_1 = []
                var yArr2_2 = []
                var yArr2_3 = []
                var yArr2_4 = []
                result.comptypecon_m_list.filter(function (item) {
                    xArr2.push(item.ben_time)
                    yArr2_1.push(item.complain_data_num)
                    yArr2_2.push(item.complain_voice_num)
                    yArr2_3.push(item.complain_other_num)
                    yArr2_4.push(item.complain_data_ratio)
                })


                var xArr3 = []
                var yArr3 = []
                $.each(result.complain_repeat_rate_list, function (index, value) {
                    if (value.city != '不详' && value.area != '不详') {
                        if (geo_dim === '省') {
                            xArr3.push(value.city)
                        } else {
                            xArr3.push(value.area)
                        }
                        yArr3.push(value.complain_repeat_rate)
                    }
                })

                var xArr5 = []
                var yArr5 = []
                $.each(result.comptypecon_m_list, function (index, value) {
                    xArr5.push(value.ben_time)
                    yArr5.push(value.com_workorder_num)
                })

                var xArr6 = []
                var yArr6 = []
                $.each(result.compscene_m_list, function (index, value) {
                    xArr6.push(value.complaint_scene)
                    yArr6.push(value.scene_complaint_ratio)
                })
                compscene_month = result.compscene_m_list[0].starttime.substring(5, 7) + '月份用户投诉TOP 10场景'
                $('#compscene_month').html(compscene_month)
                var xArr7 = []
                var yArr7_1 = []
                var yArr7_2 = []
                var yArr7_3 = []
                yArr7_3month = '', yArr7_2month = '', yArr7_1month = ''
                if (result.widetable_m_1_1_list && result.widetable_m_1_1_list.length > 0) {
                    yArr7_1month = result.widetable_m_1_1_list[0].yArr7_1month
                }
                if (result.widetable_m_1_2_list && result.widetable_m_1_2_list.length > 0) {
                    yArr7_2month = result.widetable_m_1_2_list[0].yArr7_2month
                }
                if (result.widetable_m_1_3_list && result.widetable_m_1_3_list.length > 0) {
                    yArr7_3month = result.widetable_m_1_3_list[0].yArr7_3month
                }
                var widetable_m_list = []
                widetable_m_list.push({'length': result.widetable_m_1_1_list.length, 'data': result.widetable_m_1_1_list})
                widetable_m_list.push({'length': result.widetable_m_1_2_list.length, 'data': result.widetable_m_1_2_list})
                widetable_m_list.push({'length': result.widetable_m_1_3_list.length, 'data': result.widetable_m_1_3_list})

                widetable_m_list.sort(compare(widetable_m_list, 'length'))
                $.each(widetable_m_list[0].data, function (index, value) {
                    if (value.city != '不详' && value.area != '不详') {
                        if (geo_dim === '省') {
                            xArr7.push(value.city)
                        } else {
                            xArr7.push(value.area)
                        }
                    }
                })

                $.each(xArr7, function (ind, val) {
                    var isEqual = false
                    $.each(result.widetable_m_1_1_list, function (index, value) {
                        if (value.city != '不详' && value.area != '不详') {
                            if (geo_dim === '省') {
                                if (value.city === val) {
                                    yArr7_1.push(value.return_visit_sat_rate_range)
                                    isEqual = true
                                }
                            } else {
                                if (value.area === val) {
                                    yArr7_1.push(value.return_visit_sat_rate_range)
                                    isEqual = true
                                }
                            }
                        }
                    })
                    if (!isEqual) {
                        yArr7_1.splice(ind + 1, 0, 0)
                    }

                    var isEqual_2 = false
                    $.each(result.widetable_m_1_2_list, function (index, value) {
                        if (value.city != '不详' && value.area != '不详') {
                            if (geo_dim === '省') {
                                if (value.city === val) {
                                    yArr7_2.push(value.return_visit_sat_rate_range)
                                    isEqual_2 = true
                                }
                            } else {
                                if (value.area === val) {
                                    yArr7_2.push(value.return_visit_sat_rate_range)
                                    isEqual_2 = true
                                }
                            }
                        }
                    })
                    if (!isEqual_2 && yArr7_2month) {
                        yArr7_2.splice(ind + 1, 0, 0)
                    }

                    var isEqual_3 = false
                    $.each(result.widetable_m_1_3_list, function (index, value) {
                        if (value.city != '不详' && value.area != '不详') {
                            if (geo_dim === '省') {
                                if (value.city === val) {
                                    yArr7_3.push(value.return_visit_sat_rate_range)
                                    isEqual_3 = true
                                }
                            } else {
                                if (value.area === val) {
                                    yArr7_3.push(value.return_visit_sat_rate_range)
                                    isEqual_3 = true
                                }
                            }
                        }
                    })
                    if (!isEqual_3) {
                        yArr7_3.splice(ind + 1, 0, 0)
                    }
                })
                console.log()


                // 基础通信工单量日粒度对标
                drawColumnCol({
                    id: 'line1',
                    title: null,
                    cate: xArr1,
                    data: [
                        {
                            name: ben_value_pmonth, // '前月对标值',
                            type: 'line',
                            marker: {
                                enabled: true, /* 数据点是否显示 */
                                radius: 4 /* 数据点大小px */
                            },
                            // color: N.Util.Theme_colors.orange,
                            data: ben_value_pm
                        },
                        {
                            name: ben_value_lmonth, // '上月对标值',
                            type: 'line',
                            marker: {
                                enabled: true, /* 数据点是否显示 */
                                radius: 4 /* 数据点大小px */
                            },
                            // color: N.Util.Theme_colors.orange,
                            data: ben_value_lm
                        },
                        {
                            name: ben_value_lylmonth, // '当月对标值',
                            type: 'line',
                            maxPointWidth: 15,
                            // color: N.Util.Theme_colors.blue,
                            data: ben_value_lylm
                        }
                    ],
                    marginTop: 20,
                    marginBottom: 20,
                    itemWidth: 110,
                    lenabled: true,
                    lenabledAlign: 'center',
                    lenabledVerticalAlign: 'top',
                    layout: 'horizontal'
                })

                // 投诉业务类型变化
                drawColumnCol({
                    id: 'line10',
                    title: null,
                    cate: xArr2,
                    XWidth: 1,
                    YWidth: 0,
                    data: [
                        {
                            name: '数据类投诉量',
                            type: 'column',
                            maxPointWidth: 15,
                            // color: N.Util.Theme_colors.blue,
                            data: yArr2_1,
                            yAxis: 0
                        },
                        {
                            name: '语音类投诉量',
                            type: 'column',
                            maxPointWidth: 15,
                            // color: N.Util.Theme_colors.blue,
                            data: yArr2_2,
                            yAxis: 0
                        },
                        {
                            name: '其他类投诉量',
                            type: 'column',
                            maxPointWidth: 15,
                            // color: N.Util.Theme_colors.blue,
                            data: yArr2_3,
                            yAxis: 0
                        },
                        {
                            name: '数据类投诉率(%)',
                            type: 'line',
                            maxPointWidth: 15,
                            // color: N.Util.Theme_colors.blue,
                            data: yArr2_4,
                            yAxis: 1
                        }
                    ],
                    marginTop: 30,
                    marginBottom: 30,
                    // itemWidth:110,
                    lenabled: true,
                    lenabledAlign: 'center',
                    lenabledVerticalAlign: 'top',
                    layout: 'horizontal',
                    itemDistance: 3
                })

                // 基础通信重复投诉率
                drawColumnCol({
                    id: 'line2',
                    title: null,
                    cate: xArr3,
                    XWidth: 1,
                    YWidth: 0,
                    data: [
                        {
                            name: '基础通信重复投诉率(%)',
                            type: 'column',
                            maxPointWidth: 15,
                            color: N.Util.Theme_colors.blue,
                            data: yArr3,
                            zones: [ {
                                value: 10
                                // color: N.Util.Theme_colors.blue
                            }, {
                                color: N.Util.Theme_colors.alarmRed
                            }
                            ]
                        }
                    ],
                    marginBottom: 30,
                    itemWidth: 110,
                    lenabled: false,
                    lenabledAlign: 'center',
                    lenabledVerticalAlign: 'top',
                    layout: 'horizontal'
                })

                // 2月份用户投诉行政属性划分
                try {
                    var numyseat = parseFloat(result.widetable_m_2_list[0].complain_adm_att_ratio_numyseat.toFixed(2))
                    var city = parseFloat(result.widetable_m_2_list[0].complain_adm_att_ratio_city.toFixed(2))
                    var complain_adm_att_ratio_numry = parseFloat(result.widetable_m_2_list[0].complain_adm_att_ratio_numry.toFixed(2))
                    var complain_adm_att_ratio_list = []
                    complain_adm_att_ratio_list.push({y: numyseat, name: '县城'})
                    complain_adm_att_ratio_list.push({y: city, name: '市区'})
                    complain_adm_att_ratio_list.push({y: complain_adm_att_ratio_numry, name: '农村'})
                    complain_adm_att_ratio_list.sort(compare(complain_adm_att_ratio_list, 'y'))
                    drawPie({
                        id: 'line4',
                        title: null,
                        type: 'pie',
                        data: complain_adm_att_ratio_list,
                        layout: 'vertical', // horizontal   //vertical
                        // marginRight: 100,
                        align: 'right',
                        verticalAlign: 'middle',
                        dataLabelsEnable: true
                    })
                    $('#complain_adm_att_ratio').html(result.widetable_m_2_list[0].starttime.substring(5, 7) + '月份用户投诉行政属性划分')
                } catch (e) {
                    console.log(e)
                }

                // 18年-19年基础通信工单量变化
                drawColumnCol({
                    id: 'line5',
                    title: null,
                    cate: xArr5,
                    data: [
                        {
                            name: '基础通信工单量',
                            type: 'line',
                            marker: {
                                enabled: true, /* 数据点是否显示 */
                                radius: 4 /* 数据点大小px */
                            },
                            color: N.Util.Theme_colors.orange,
                            data: yArr5
                        }
                    ],
                    marginTop: 30,
                    marginBottom: 30,
                    itemWidth: 110,
                    lenabled: false,
                    lenabledAlign: 'center',
                    lenabledVerticalAlign: 'bottom',
                    layout: 'horizontal'
                })

                // 2月份用户投诉TOP 10场景
                drawColumnCol({
                    id: 'line6',
                    title: null,
                    cate: xArr6,
                    data: [
                        {
                            name: '投诉率(%)',
                            type: 'column',
                            maxPointWidth: 15,
                            color: N.Util.Theme_colors.blue,
                            data: yArr6
                        }
                    ],
                    marginTop: 30,
                    marginBottom: 30,
                    itemWidth: 110,
                    lenabled: false,
                    lenabledAlign: 'center',
                    lenabledVerticalAlign: 'top',
                    layout: 'horizontal'
                })

                // 近3个月地市回访满意率变化
                drawColumnCol({
                    id: 'line11',
                    title: null,
                    cate: xArr7,
                    data: [
                        {
                            name: yArr7_2month, // '前月',
                            type: 'column',
                            maxPointWidth: 15,
                            // color: N.Util.Theme_colors.red,
                            data: yArr7_2,
                            zones: [ {
                                value: 50,
                                color: N.Util.Theme_colors.alarmRed
                            }
                            ]
                        },
                        {
                            name: yArr7_1month, // '上月',
                            type: 'column',
                            maxPointWidth: 15,
                            // color: N.Util.Theme_colors.blue,
                            data: yArr7_1,
                            zones: [ {
                                value: 50,
                                color: N.Util.Theme_colors.alarmRed
                            }
                            ]
                        },
                        {
                            name: yArr7_3month, // '当月',
                            type: 'column',
                            maxPointWidth: 15,
                            // color: N.Util.Theme_colors.red,
                            data: yArr7_3,
                            zones: [ {
                                value: 50,
                                color: N.Util.Theme_colors.alarmRed
                            }
                            ]
                        }
                    ],
                    marginTop: 30,
                    marginBottom: 30,
                    itemWidth: 110,
                    lenabled: false,
                    lenabledAlign: 'center',
                    lenabledVerticalAlign: 'top',
                    layout: 'horizontal'
                })
                loading.hide()
            }
        })
    }
})
var page = new N.complain2()

$(function () {
    $(document).on('map:click', function (event, geography, shiduan, geo_dim, map_city, map_area) {
        page.pageLoad(geography, shiduan, geo_dim, map_city, map_area)
    })
})



